/*
 * @Description: 
 * @Author: Aroma
 * @Date: 2024-09-19 20:48:24
 * @LastEditors: Aroma
 * @LastEditTime: 2024-09-19 20:48:54
 * @别瞎看: 你个无脑牛马
 */
public class Test14{
    public static void main(String[] args) {
        Cylinder cylinder = new Cylinder(5, 10);
        
        // 调用Cylinder的方法
        System.out.println("Cylinder Area: " + cylinder.calculateArea());
        System.out.println("Cylinder Volume: " + cylinder.calculateVolume());
        System.out.println(cylinder.toString());
        
        // Circle类型的引用指向Cylinder对象
        Circle circleRef = cylinder;
        
        // Circle类型引用可以调用Circle类定义的方法
        System.out.println("Area through Circle ref: " + circleRef.calculateArea()); // 这里将调用Cylinder重写的calculateArea()
        System.out.println(circleRef.toString()); // 这里将调用Cylinder重写的toString()
        
        // Circle类型引用不能直接调用Cylinder特有的方法，比如calculateVolume()
        // 下面这行代码是编译错误的，因为Circle类没有calculateVolume()方法
        // System.out.println("Volume through Circle ref: " + circleRef.calculateVolume());
        
        // 若要调用Cylinder的calculateVolume()，需要将引用强制类型转换为Cylinder类型
        if (circleRef instanceof Cylinder) {
            Cylinder cylinderRef = (Cylinder) circleRef;
            System.out.println("Volume through casted Cylinder ref: " + cylinderRef.calculateVolume());
        }
    }
}